//
//  AXFTypeCollectionViewCell.m
//  aixinfeng005
//
//  Created by zhanghaifeng on 16/10/11.
//  Copyright © 2016年 BBSWaitting. All rights reserved.
//

#import "AXFTypeCollectionViewCell.h"
#import "AXFTypeModel.h"

@interface AXFTypeCollectionViewCell()

@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UILabel *nameLabel;

@end

@implementation AXFTypeCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        // 添加子空间
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    // 创建显示图片的ImageView
    UIImageView *iconView = [[UIImageView alloc] init];
    [self.contentView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
        make.top.offset(8);
        make.width.height.offset(30);
    }];
    
    // 创建显示名称的Label
    
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = [UIColor darkGrayColor];
    // 设置label中的文字局中
    nameLabel.textAlignment = NSTextAlignmentCenter;
    // 设置字体
    nameLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:nameLabel];
    [self.contentView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(iconView.mas_bottom).offset(8);
    }];
    
    self.iconView = iconView;
    self.nameLabel = nameLabel;
    
}

- (void)setTypeModel:(AXFTypeModel *)typeModel{
    
    _typeModel = typeModel;
    self.iconView.image = [UIImage imageNamed:_typeModel.icon];
    self.nameLabel.text = _typeModel.name;
}

// 重写高亮属性的set方法在此方法中设置cell的背景颜色
// 点击和松手都会调用方法
- (void)setHighlighted:(BOOL)highlighted {
    
    self.backgroundColor = highlighted ? [UIColor colorWithWhite:0.9 alpha:1] : [UIColor whiteColor];
}

@end
